const Stock = require('../db/model/stock');
//const Entries = require('../../db/models/Entries');
const stockHelper = require('./testHelpers/stockHelper');
//const entrieshelper = require('../testHelpers/entriesHelper');

//Require the dev-dependencies
const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('../bin/www');
const expect = chai.expect;

chai.use(chaiHttp);

describe('Stock', () => {
    before(async () => {
        // Empty out the entries
        await Stock.query().delete();
    });

    describe('add', async () => {
        it('should add', async () => {

            let addReq = await stockHelper
                .add(
                    chai.request(server),
                    'ddddd',
                    '111111',
                    'tlys'
                );

            // Make sure you were able to login
            expect(addReq.status).to.equal(200);

            // Extract token from the response
            console.log(addReq.body)
            
            let id = addReq.body.data.id;

            // Send the add entry response
            let getReq = await stockHelper
                .get(
                    chai.request(server),
                    id
                )

            // Make sure the request went well
            expect(getReq.status).to.equal(200);

            let name = getReq.body.data.name;
            expect(name).to.equal('ddddd');     

            let entry = await Stock.query().findOne({});
            expect(entry.name).to.equal('ddddd');

            //  update
        });

    });
});